package pl.kosmowska.ewelina.client.views.widgets.dialogs;

import pl.kosmowska.ewelina.client.views.widgets.dialogs.OptionEvent.Selected;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.safehtml.shared.SimpleHtmlSanitizer;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.Widget;

public class ThreeOptionDialog extends DialogBox {

  private static ThreeOptionDialogUiBinder uiBinder = GWT.create(ThreeOptionDialogUiBinder.class);
  @UiField HorizontalPanel pMessage;
  @UiField HTML htmlMessage;
  @UiField PushButton bNo;
  @UiField PushButton firstOption;
  @UiField PushButton secondOption;
  @UiField PushButton thirdOption;
  
  
  interface ThreeOptionDialogUiBinder extends UiBinder<Widget, ThreeOptionDialog> {
  }

  public ThreeOptionDialog(String message) {
    setWidget(uiBinder.createAndBindUi(this));
    
    setMessage(message);
  }
  
  public void setMessage(String message) {
    if (message == null) {
      htmlMessage.setHTML("");
    }
    htmlMessage.setHTML(SimpleHtmlSanitizer.sanitizeHtml(message));
  }
  
  public void setOptionsText(String optionText1, String optionText2,String optionText3) {
	  firstOption.setText(optionText1);
	  secondOption.setText(optionText2);
	  thirdOption.setText(optionText3);
  }
  
  @UiHandler("bNo")
  void onBNoClick(ClickEvent event) {
    hide();
    fireEvent(new OptionEvent(Selected.FALSE));
  }
  
  public HandlerRegistration addSelectionHandler(OptionEventHandler handler) {
    return addHandler(handler, OptionEvent.TYPE);
  }
  
  @UiHandler("firstOption")
  void onFirstOptionClick(ClickEvent event) {
	  hide();
	  fireEvent(new OptionEvent(Selected.OPTION_1));
  }
  @UiHandler("secondOption")
  void onSecondOptionClick(ClickEvent event) {
	  hide();
	  fireEvent(new OptionEvent(Selected.OPTION_2));
  }
  @UiHandler("thirdOption")
  void onThirdOptionClick(ClickEvent event) {
	  hide();
	  fireEvent(new OptionEvent(Selected.OPTION_3));
  }
}
